﻿using IdentityModel;
using System;
using System.Security.Cryptography;
using System.Text;

namespace Gen_CodeVerifier
{
    class Program
    {
        static void Main(string[] args)
        {
            // generate code_verifier
            var codeVerifier = CryptoRandom.CreateUniqueId(32);

            // store codeVerifier for later use


            // create code_challenge
            string codeChallenge;
            using (var sha256 = SHA256.Create())
            {
                var challengeBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(codeVerifier));
                codeChallenge = Base64Url.Encode(challengeBytes);
            }

            // add code_challenge and code_challenge_method to request
            //context.ProtocolMessage.Parameters.Add("code_challenge", codeChallenge);
            //context.ProtocolMessage.Parameters.Add("code_challenge_method", "S256");

            string s = $"code_challenge={codeChallenge}&code_challenge_method=S256";
            Console.WriteLine(codeVerifier);
            Console.WriteLine(s);
        }
    }
}
